| Conditions | 5 |
| Paths | 7 |
| Total Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | // Copyright © 2017 TangDongxin |
||
| 24 | function onParse(result) { |
||
|
|
|||
| 25 | var chrome = this.chrome || this.browser; |
||
| 26 | var jsonRe = /^\s*(?:\[\s*(?=-?\d|true|false|null|["[{])[^]*\]|\{\s*"[^]+\})\s*$/; |
||
| 27 | var body = document.body; |
||
| 28 | var str, jsonpMatch, tag; |
||
| 29 | |||
| 30 | console.log(strictOnly); |
||
| 31 | if (strictOnly) { |
||
| 32 | // only render when the contentType is json |
||
| 33 | if (/[+\/]json$/i.test(document.contentType)) { |
||
| 34 | init(); |
||
| 35 | str = body.textContent; |
||
| 36 | draw(str, body); |
||
| 37 | } |
||
| 38 | } else { |
||
| 39 | // check whether the content is json or like json |
||
| 40 | try { |
||
| 41 | if (jsonRe.test(body.textContent)) { |
||
| 42 | init(); |
||
| 43 | draw(first.textContent, body); |
||
| 44 | } |
||
| 45 | } catch (e) { |
||
| 46 | dlog(e); |
||
| 47 | // ignore |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | function init() { |
||
| 52 | if (tag) { |
||
| 53 | return; |
||
| 54 | } |
||
| 55 | |||
| 56 | tag = document.createElement("style"); |
||
| 57 | tag.textContent = [ |
||
| 58 | '.R', ',.D', '{font:' + fontSize + ' ' + fontStyle + '}' + |
||
| 59 | '.D', '{margin-left:0.5em; padding-left:2em; margin-top: 1px; border-left:1px dashed; border-color: #93A1A1;}' + |
||
| 60 | '.X', '{border:1px solid #ccc; padding:1em}' + |
||
| 61 | 'a.L', '{text-decoration:none}' + |
||
| 62 | 'a.L', ':hover,a.L', ':focus{text-decoration:underline}' + |
||
| 63 | 'i.I', '{cursor:pointer;color:#ccc}' + |
||
| 64 | 'i.H', ',i.I', ':hover{text-shadow: 1px 1px 3px #999; color:#333}' + |
||
| 65 | 'i.I', ':before{content:" ▼ "}' + |
||
| 66 | 'i.C', ':before{content:" ▶ "}' + |
||
| 67 | 'i.C', '+.D', '{width:1px; height:1px; margin:0; padding:0; border:0; display:inline-block; overflow:hidden}' + |
||
| 68 | '.S', '{color:' + strColor + '}' + // string |
||
| 69 | '.K', '{color:' + keyColor + '}' + // key |
||
| 70 | '.E', '{color:#BCADAD}' + // error |
||
| 71 | '.B', '{color:' + intColor + '}' + // number and bool |
||
| 72 | '.E', ',.B', '{font-style: italic}' + // number bold |
||
| 73 | 'h3.E', '{margin:0 0 1em}' |
||
| 74 | ].join(RAND); |
||
| 75 | |||
| 76 | tag.textContent += 'i.I' + RAND + ':after{content:attr(data-content)}'; |
||
| 77 | tag.textContent += 'body {background: ' + bgColor + '; color:' + defaultColor + ';}'; |
||
| 78 | tag.textContent += '.HIDE {width:200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }'; |
||
| 79 | tag.textContent += '* {font:' + fontSize + ' ' + fontStyle + ' !important;}'; |
||
| 80 | tag.textContent += '.black_overlay{ display: none; position: fixed; top: 0%; left: 0%; width: 100%; height: 100%; background-color: black; z-index:1001; -moz-opacity: 0.6; opacity:.60; filter: alpha(opacity=60); }'; |
||
| 81 | tag.textContent += '.white_content { display: none; position: fixed; top: 10%; left: 13%; width: 70%; min-width: 500px; min-height: 300px; height: 60%; padding: 1%; border: 16px solid orange; background-color: white; z-index:1002; overflow: auto; }'; |
||
| 82 | tag.textContent += 'str:hover{text-shadow: 1px 1px 3px #999; color:#333}'; |
||
| 83 | tag.textContent += 'json:hover{text-shadow: 1px 1px 3px #999; color:#333}'; |
||
| 84 | |||
| 85 | document.head.appendChild(tag); |
||
| 86 | } |
||
| 87 | } |
||
| 88 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.